package com.senven.common.user.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class UpdateInsert implements MetaObjectHandler {

        //当添加时删除状态的值
        @Override
        public void insertFill(MetaObject metaObject) {
            log.info("start insert fill ....");
             this.strictInsertFill(metaObject, "gmtCreate",
                    () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
            this.strictInsertFill(metaObject, "isDeleted", () -> 0, Integer.class);
           this.strictInsertFill(metaObject, "isDeleted", () -> false,Boolean.class); // 起始版本3.3.3(推荐)

        }
        //当删除时自动填充的值
        @Override
        public void updateFill(MetaObject metaObject) {
//            log.info("start update fill ....");
//            this.strictUpdateFill(metaObject, "gmtModiffed",
//                    () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
//            this.strictInsertFill(metaObject, "isDeleted", () -> 1, Integer.class);
//            this.strictInsertFill(metaObject, "isDeleted", () -> true,Boolean.class); // 起始版本3.3.3(推荐)
        }





}
